module utils.Playlink;

import utils.CommonTool : CommonTool;

/** 
 * 处理播放链接的类
 */
class Playlink
{

    /** 
     * 获取真实播放地址
     * Params:
     *   url = string = 原播放地址
     * Returns: string
     */
    public static string getRealPlaylink (string url)
    {
        import std.string : tr;
        import std.regex : ctRegex, matchFirst;

        string htmlStr = CommonTool.getHtml(url);

        // auto rex = ctRegex!(`"url":"(.*?)","url_next"`);
        auto rex = ctRegex!(`\},"url":"(.*?)","url_next"`);
        auto match = matchFirst(htmlStr, rex);
        if (match.empty)
        {
            return null;
        }

        string realUrl = tr(match[1], `\`, "", "d");
        return realUrl;
    }
}
